Matrix Reduction

Matrices (two-dimensional arrays) are used by mathematicians, astronomers, graphics programmers and roboticists. Here's a simple matrix manipulation example. Fill in the matrix below and press the [Reduce] button to mathematically reduce it to an upper triangular matrix.



Discussion

This applet introduces the use of two-dimensional arrays. These matrices are created by storing a series of one-dimensional arrays in a master array. Once created, the matrix can be addressed by successive brackets, such as matrix[2][1], matrix[0][2], etc.

The form is also addressed in row-column format. This applet codes the indices into the form name. (e.g. J21, J02, etc).

//-------------MATRIX CREATION----------------

// Create row of a given size
function matrixRow(row, side)
{
    for (var i = 0; i < side; i++) 
        this[i] = ((i == row) ? 1 : 0)
    this.length = side
    return this
}

// Create matrix of size: side x side
function makeMatrix(side)
{
    for (var i = 0; i < side; i++) 
        this[i] = new matrixRow(i, side)
    this.length = side
    return this
}

//-------------2-D FORM----------------
<FORM>

<INPUT NAME="J00" SIZE=6>
    <INPUT NAME="J01" SIZE=6>
    <INPUT NAME="J02" SIZE=6><p>
<INPUT NAME="J10" SIZE=6>
    <INPUT NAME="J11" SIZE=6>
    <INPUT NAME="J12" SIZE=6><p>
<INPUT NAME="J20" SIZE=6>
    <INPUT NAME="J21" SIZE=6>
    <INPUT NAME="J22" SIZE=6><p>

<INPUT TYPE="BUTTON" VALUE="Reinit" onClick="initMatrix()">
<INPUT TYPE="BUTTON" VALUE="Reduce" onClick="doit()">

</FORM>
Copyright ©1998 by Charles River Media, All Rights Reserved